package acm.pta11;

import java.util.Scanner;
import java.util.Stack;

public class 简单计算器 {
    public static void main(String[] args) {
        Stack<Integer> stack = new Stack<>();
        String[] symbol=null;
        Scanner sc=new Scanner(System.in);
        try {
            int n=sc.nextInt();
            while (n-- > 0) {
                stack.push(sc.nextInt());
            }
            sc.nextLine();
            symbol=sc.nextLine().split(" ");
            for (int i = symbol.length - 1; i >= 0; i--) {
                Integer right = stack.pop();
                Integer left = stack.pop();
                int res = calculate(symbol[i], left, right);
                stack.push(res);
            }
            System.out.println(stack.pop());
        }catch (Exception e){

        }
    }
    public static int calculate(String s,int left,int right) {
        try {
            switch (s) {
                case "+":
                    return left + right;
                case "-":
                    return left - right;
                case "*":
                    return left * right;
                case "/":
                    return left / right;
                default:
                    return 0;
            }
        }catch (Exception e){
            System.out.println("ERROR: "+left+"/0");
            throw e;
        }
    }
}
